package com.lex.controller;

import com.lex.common.annoatation.SysLog;
import com.lex.common.api.CommonResult;
import com.lex.data.admin.model.LexCmsMenu;
import com.lex.entity.params.MenuQueryParams;
import com.lex.service.MenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.lex.common.enums.BusinessType;

/**
 * @ClassName MenuController
 * @Description 菜单管理控制器，用于处理菜单管理相关请求
 */
@RestController
@RequestMapping("/")
@Tag(name = "MenuController", description = "菜单接口")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @Operation(summary = "获取用户菜单列表")
    @RequestMapping(value = "/getMenus", method = RequestMethod.GET)
    public CommonResult getMenus(){
        return menuService.getUserMenuList();
    }

    @Operation(summary = "获取用户所有权限标识，权限控制粒度更细")
    @RequestMapping(value = "/getPermCode", method = RequestMethod.GET)
    public CommonResult getPermCode(){
        return menuService.getUserPermCode();
    }

    @Operation(summary = "获取所有菜单列表,只能平台用户管理菜单，租户不能管理菜单，权限要控制好")
    @RequestMapping(value = "/getAllMenus", method = RequestMethod.GET)
    public CommonResult getAllMenus(MenuQueryParams queryParams,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @RequestParam(defaultValue = "1") Integer page){
        return menuService.getAllMenuList(queryParams, pageSize, page);
    }

    @SysLog(title = "删除菜单", businessType = BusinessType.DELETE)
    @Operation(summary = "删除菜单，上线后不建议删除菜单")
    @RequestMapping(value = "/deleteMenu/{menuId}", method = RequestMethod.DELETE)
    public CommonResult deleteMenu(@PathVariable Long menuId){
        return menuService.deleteMenu(menuId);
    }

    @SysLog(title = "添加菜单", businessType = BusinessType.INSERT)
    @Operation(summary = "添加菜单")
    @RequestMapping(value = "/addMenu", method = RequestMethod.POST)
    public CommonResult addMenu(@RequestBody LexCmsMenu menu){
        return menuService.addMenu(menu);
    }

    @SysLog(title = "修改菜单", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改菜单")
    @RequestMapping(value = "/updateMenu", method = RequestMethod.PUT)
    public CommonResult updateMenu(@RequestBody LexCmsMenu menu){
        return menuService.updateMenu(menu);
    }

    @Operation(summary = "获取角色所有菜单列表")
    @RequestMapping(value = "/getRoleAllMenu", method = RequestMethod.GET)
    public CommonResult getRoleAllMenu(){
        return menuService.getRoleAllMenu();
    }


}
